package com.gqj.elec.controller;

import com.gqj.common.annotation.Log;
import com.gqj.common.core.controller.BaseController;
import com.gqj.common.core.domain.AjaxResult;
import com.gqj.common.core.page.TableDataInfo;
import com.gqj.common.enums.BusinessType;
import com.gqj.common.utils.poi.ExcelUtil;
import com.gqj.elec.domain.ElecMaterialOutdetail;
import com.gqj.elec.service.IElecMaterialOutdetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 物资出库详情Controller
 *
 * @author lxq
 * @date 2023-12-17
 */
@RestController
@RequestMapping("/elec/elecMaterialOutDetail")
public class ElecMaterialOutdetailController extends BaseController {
    @Autowired
    private IElecMaterialOutdetailService elecMaterialOutdetailService;

    /**
     * 查询物资出库详情列表
     */
    @PreAuthorize("@ss.hasPermi('elec:elecMaterialOutDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ElecMaterialOutdetail elecMaterialOutdetail) {
        startPage();
        List<ElecMaterialOutdetail> list = elecMaterialOutdetailService.selectElecMaterialOutdetailList(elecMaterialOutdetail);
        return getDataTable(list);
    }

    /**
     * 导出物资出库详情列表
     */
    @PreAuthorize("@ss.hasPermi('elec:elecMaterialOutDetail:export')")
    @Log(title = "物资出库详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElecMaterialOutdetail elecMaterialOutdetail) {
        List<ElecMaterialOutdetail> list = elecMaterialOutdetailService.selectElecMaterialOutdetailList(elecMaterialOutdetail);
        ExcelUtil<ElecMaterialOutdetail> util = new ExcelUtil<ElecMaterialOutdetail>(ElecMaterialOutdetail.class);
        util.exportExcel(response, list, "物资出库详情数据");
    }

    /**
     * 获取物资出库详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('elec:elecMaterialOutDetail:query')")
    @GetMapping(value = "/{outdetailId}")
    public AjaxResult getInfo(@PathVariable("outdetailId") Long outdetailId) {
        return AjaxResult.success(elecMaterialOutdetailService.selectElecMaterialOutdetailByOutdetailId(outdetailId));
    }

    /**
     * 新增物资出库详情
     */
    @PreAuthorize("@ss.hasPermi('elec:elecMaterialOutDetail:add')")
    @Log(title = "物资出库详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElecMaterialOutdetail elecMaterialOutdetail) {
        return toAjax(elecMaterialOutdetailService.insertElecMaterialOutdetail(elecMaterialOutdetail));
    }

    /**
     * 修改物资出库详情
     */
    @PreAuthorize("@ss.hasPermi('elec:elecMaterialOutDetail:edit')")
    @Log(title = "物资出库详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElecMaterialOutdetail elecMaterialOutdetail) {
        return toAjax(elecMaterialOutdetailService.updateElecMaterialOutdetail(elecMaterialOutdetail));
    }

    /**
     * 删除物资出库详情
     */
    @PreAuthorize("@ss.hasPermi('elec:elecMaterialOutDetail:remove')")
    @Log(title = "物资出库详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{outdetailIds}")
    public AjaxResult remove(@PathVariable Long[] outdetailIds) {
        return toAjax(elecMaterialOutdetailService.deleteElecMaterialOutdetailByOutdetailIds(outdetailIds));
    }

    /**
     * 提交通道门识别
     */
    @PostMapping("/submitMaterialInfo")
    public AjaxResult submitMaterialInfo(@RequestBody ElecMaterialOutdetail elecMaterialOutdetail) {
        return AjaxResult.success(elecMaterialOutdetailService.detailMaterialInfo(elecMaterialOutdetail));
    }
}
